package com._5704.website.util;

import com._5704.website.entity.Code;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;


import java.util.Date;

@Component
@Deprecated
public class CodeUtil {


    private static int expiredTime;

    private static int length;

    @Value("${email.code.expiredTime}")
    private   void setExpiredTime(int expiredTimeIn) {
        expiredTime = expiredTimeIn;
    }
    @Value("${email.code.length}")
    private void setLength(int lengthIn) {
        length = lengthIn;
    }

    public static Code init(){
        return new Code()
                .setCode(GetRandomUtil.getRandomCode(length))
                .setDate(new Date());
    }

    public static boolean  isExpired(Code code){
        return !code.getDate().after(new Date(System.currentTimeMillis() - expiredTime));
    }

    public static boolean  isEqual(Code code,String code2){
        return code.getCode().equals(code2);
    }
}
